/**
 * Created by ajhin on 7/11/2015.
 */
package com.societyGames2.convert
{
import org.as3commons.asblocks.parser.antlr.LinkedListTree;
import org.as3commons.asblocks.parser.antlr.as3.AS3Parser;

public class VarDecTreeConverter implements ITreeConverter
{
  //ITreeToCSharp-->
  public function convert(tree:LinkedListTree):String
  {
    var identTree:LinkedListTree;
    var typeSpecTree:LinkedListTree;
    var assignTree:LinkedListTree;
    var childTree:LinkedListTree
    for (var i:int = 0; tree.children != null && i < tree.children.length; i++)
    {
      childTree = LinkedListTree(tree.getChild(i));
      if (childTree.type == AS3Parser.IDENT)
      {
        identTree = childTree;
      }
      else if (childTree.type == AS3Parser.TYPE_SPEC)
      {
        typeSpecTree = childTree;
      }
      else if (childTree.type == AS3Parser.ASSIGN)
      {
        assignTree = childTree;
      }
    }
    var source:String = TreeConverters.convert(typeSpecTree); //int
    source += " " + TreeConverters.convert(identTree); //count
    if (assignTree != null)
    {
      source += " = " + TreeConverters.tokenTreeConverter.convert(assignTree);
    }
    return source;
  }
  //<--ITreeToCSharp
}
}
